import datetime


def get_headers(requestverificationtoken=None):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                      'Chrome/122.0.0.0 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest'
    }

    if requestverificationtoken is not None:
        headers['requestverificationtoken'] = requestverificationtoken;
    return headers


def get_form_data(tree):
    form = tree.xpath('//form')[0]
    # 获取表单数据
    form_data = {}
    for input_ele in form.xpath('.//input'):
        input_name = input_ele.get('name')
        input_value = input_ele.get('value')
        if input_name:
            form_data[input_name] = input_value or ''

    return form_data


def datetime_handler(x):
    if isinstance(x, datetime.datetime):
        return x.isoformat()
    raise TypeError("Unknown type")
